﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using igflow.GameObject;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace igflow
{
    class QuadMesh : Mesh
    {
        public QuadMesh(float w, float h)
        {
            //Textures = new List<Texture2D>();
            //Textures.Add(World.contentManager.Load<Texture2D>("texture"));
            vertexDeclaration = new VertexDeclaration(World.Graphics.GraphicsDevice, VertexPositionColorTexture.VertexElements);

            Vertices = new VertexPositionColorTexture[4];
            Indexes = new short[6];

            // Fill in texture coordinates to display full texture
            // on quad
            Vector2 textureUpperLeft = new Vector2(0.0f, 0.0f);
            Vector2 textureUpperRight = new Vector2(1.0f, 0.0f);
            Vector2 textureLowerLeft = new Vector2(0.0f, 1.0f);
            Vector2 textureLowerRight = new Vector2(1.0f, 1.0f);

            // Set the position and texture coordinate for each
            // vertex
            Vertices[0].Position = new Vector3(-w / 2, -h / 2, 0);
            Vertices[0].TextureCoordinate = textureLowerLeft;
            Vertices[0].Color = Color.Red;

            Vertices[2].Position = new Vector3(w / 2, -h / 2, 0);
            Vertices[2].TextureCoordinate = textureLowerRight;
            Vertices[2].Color = Color.Green;

            Vertices[1].Position = new Vector3(-w / 2, h / 2, 0);
            Vertices[1].TextureCoordinate = textureUpperLeft;
            Vertices[1].Color = Color.Blue;

            Vertices[3].Position = new Vector3(w / 2, h / 2, 0);
            Vertices[3].TextureCoordinate = textureUpperRight;
            Vertices[3].Color = Color.White;

            // Set the index buffer for each vertex, using
            // clockwise winding
            Indexes[0] = 0;
            Indexes[1] = 1;
            Indexes[2] = 2;
            Indexes[3] = 2;
            Indexes[4] = 1;
            Indexes[5] = 3;
        }
    }
}
